package com.pro.schedule.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pro.schedule.entity.Memo;
import com.pro.schedule.service.MemoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class MemoController {
    @Resource
    MemoService memoService;

    @ApiOperation("获取当天备忘录")
    @PostMapping("/schedule/memo/getList")
    public IPage<Memo> getMemoIPage(@RequestBody Memo memo, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return memoService.getMemoIPage(token, memo.getPage(), memo.getMemoDate());
    }

    @ApiOperation("保存或修改备忘录")
    @PostMapping("/schedule/memo/saveOrUpdate")
    public String saveOrUpdateMemo(@RequestBody Memo memo, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        return memoService.saveOrUpdateMemo(token, memo);
    }

    @ApiOperation("删除指定备忘录")
    @PostMapping("/schedule/memo/delete")
    public String deleteMemo(@RequestBody Memo memo) throws Exception {
        return memoService.deleteMemo(memo.getMemoId());
    }

    @ApiOperation("获取备忘录数量")
    @PostMapping("/schedule/memo/getCount")
    public int getMemoCount(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return memoService.getMemoCount(token);
    }

}
